package com.jt.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.service.DubboItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ItemController {

    @Reference(check = false)//启动时是否检验有服务的提供者,设置为false则先启动生产者还是消费者都不会报错了
    private DubboItemService ItemService;

    /**
     * 根据id查询商品信息
     * url: http://www.jt.com/items/562379.html
     * 参数: 562379 restFul风格
     * 返回值: String
     * 页面取值操作
     *      ${item.title }          获取商品信息   同步取值
     *      ${itemDesc.itemDesc }   获取商品详情信息
     * @param itemId
     * @return
     */
    @RequestMapping("/items/{itemId}")
    public String item(@PathVariable Long itemId, Model model){
        Item item = ItemService.findItemById(itemId);
        ItemDesc itemDesc = ItemService.findItemDescById(itemId);
        //跳转商品展示页面
        model.addAttribute("item",item);
        model.addAttribute("itemDesc",itemDesc);
        return "item";
    }
}
